﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Kinect_Interface_Prototype_1.Interface_Design
{
    public partial class LargeCheckBox : UserControl
    {
        private bool isChecked;
        public bool Checked { get{ return isChecked; } set{ ToggleChecked(value); } }

        public LargeCheckBox(int x, int y)
        {
            InitializeComponent();
            this.Location = new Point(x, y);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
            ToggleChecked(false);
        }

        public LargeCheckBox(bool value, int x, int y)
        {
            InitializeComponent();
            this.Location = new Point(x, y);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
            ToggleChecked(value);
        }

        private void ToggleChecked(bool value)
        {
            isChecked = value;
            this.BackgroundImage = isChecked ? Constants.CheckBoxClicked : Constants.CheckBoxNotClicked;
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            this.BackgroundImage = Constants.CheckBoxDown;

            base.OnMouseDown(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            Point mousePosition = Control.MousePosition;
            Point location = this.PointToClient(mousePosition);

            isChecked = location.X >= 0 && location.X <= this.Width && location.Y >= 0 && location.Y <= this.Height
                        ? !isChecked
                        : isChecked;

            ToggleChecked(isChecked);

            base.OnMouseUp(e);
        }
    }
}
